<?PHP
	/************************************************************************
	*       This file, in addition to all other parts of X7 Chat are        *
	*                   Copyright 2003-2007 by Tim Chamness.                *
	* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
	* Version:          X7 Chat 3.0.0-A2                                    *
	* Release Date:     October 20, 2007                                    *
	* Author:           Tim Chamness                                        *
	* Copyright:        2003-2007 by Tim Chamness                           *
	* Website:          http://www.x7chat.com/                              *
	* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
	* X7 Chat 3 is free software; you can redistribute it and/or modify     *
	* it under the terms of the GNU General Public License as published by  *
	* the Free Software Foundation; either version 3 of the License, or     *
	* (at your option) any later version.                                   *
	*                                                                       *
	* X7 Chat 3 is distributed in the hope that it will be useful, but      *
	* WITHOUT ANY WARRANTY; without even the implied warranty of            *
	* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
	* General Public License for more details.                              *
	*                                                                       *
	* You should have received a copy of the GNU General Public License     *
	* along with this program.  If not, see <http://www.gnu.org/licenses/>. *
	*                                                                       *
	* Additional Terms, compatible with Section 7 of the GNU GPL v3,        *
	* apply to X7 Chat 3 and all X7 Chat 3 files, including this one.       *
	* You should have received a copy of these Additional Terms in the      *
	* file docs/COPYING.ADDITIONAL_TERMS.  If you did not receive a copy    *
	* please visit <http://www.x7chat.com/COPYING.ADDITIONAL_TERMS/>.       *
	************************************************************************/

	$GLOBALS['OUTPUT']->master_section = 'settings';
	$GLOBALS['OUTPUT']->minor_section = $GLOBALS['LANG']->lang_admin->events;
	$GLOBALS['OUTPUT']->cpmenu = $menus[$GLOBALS['OUTPUT']->master_section];
	
	$data = array();
	$query = $GLOBALS['DATABASE']->get('system','events');
	$data = $query->get_next();
		
	$data['key'] = 'events';
	
	$add = x7in::read('eventdescription');
	if(!empty($add)){
		$day = x7in::read('day','i');
		$month = x7in::read('month','i');
		$year = x7in::read('yeah','i');
		$hour = x7in::read('hour','i');
		$minute = x7in::read('minute','i');
		$time = gmmktime($hour,$minute,0,$month,$day,$year);
		
		$data[$time] = array('time'=>$time,'description'=>$add);
		$GLOBALS['DATABASE']->put('system',$data);
	}
	
	$delete = x7in::read('delete','i');
	if(!empty($delete)){
		if(isset($data[$delete])){
			unset($data[$delete]);
			$GLOBALS['DATABASE']->put('system',$data);
		}
	}
	
	$pager = new lib_pager(count($data));
	
	$form = new form();
	$form->add_field('text','eventdescription',$GLOBALS['LANG']->lang_admin->eventdescription);
	$form->add_field('text','day',$GLOBALS['LANG']->lang_admin->day);
	$form->add_default('day',date('j'));
	$form->add_field('text','month',$GLOBALS['LANG']->lang_admin->month);
	$form->add_default('month',date('n'));
	$form->add_field('text','year',$GLOBALS['LANG']->lang_admin->year);
	$form->add_default('year',date('Y'));
	$form->add_field('text','hour',$GLOBALS['LANG']->lang_admin->hour);
	$form->add_default('hour',date('G'));
	$form->add_field('text','minute',$GLOBALS['LANG']->lang_admin->minute);
	$form->add_default('minute',date('i'));
	
	$GLOBALS['OUTPUT']->events = $pager->get_page_data($data);
	$GLOBALS['OUTPUT']->page = $pager->get_page();
	$GLOBALS['OUTPUT']->pages = $pager->get_pages();
	$GLOBALS['OUTPUT']->form = $form->get_fields();

	echo tpl_events::events();
?>